<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="/WEB-INF/views/modules/commons/head.jsp" %>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <style>
        .nav {
            margin-left: 0;
        }

        .nav > li > a:focus, .nav > li > a:hover {
            text-decoration: none;
            background-color: #33CCFF !important;
        }

        #gview_gridTable .ui-jqgrid-bdiv {
            max-height: 450px;
        !important;
        }

        #main-container {
            padding: 50px 20px 0;
            position: relative;

            height: calc(100% - 71px);
            width: calc(100% - 19.5%);
            margin-left: 17.5%;
            margin-top: 60px;
        }

        .modal-dialog {
            z-index: 9999999;
        }

        @media (min-width: 768px) {
            .modal-content {
                -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
                box-shadow: 0 -2px 20px rgba(0, 0, 0, .5) !important;
            }
        }

        .search-row {
            margin-left: 7px !important;
        }
    </style>
</head>
<body class="bgcolor">
<%@ include file="/WEB-INF/views/modules/commons/nav.jsp" %>
<%@ include file="/WEB-INF/views/modules/commons/menu.jsp" %>


<!-- /section:basics/navbar.layout -->
<table></table>
<div class="main-container" id="main-container">
    <%--搜索查询--%>
    <div class="row search-row">
        <div class="col-xs-2">
            <input type="text" class="form-control" id="searchWord"
                   placeholder="请输入要搜索的关键词">
        </div>
        <div class="col-xs-1" style="right: 23px;">
            <button class="btn btn-large btn-primary" id="query">搜索</button>
        </div>
        <div class="col-xs-2" style="right: 74px;">
            <select id="branchDeptType_select" class="form-control">
                <option value="">选择统计类别</option>
                <option value="">全部类别</option>
                <option value="0F">业主单位个人排名</option>
                <option value="0T">业主单位单位排名</option>
                <option value="1F">审批部门个人排名</option>
                <option value="1T">审批部门单位排名</option>
                <option value="4F">督查组排名</option>
                <option value="5">攻坚任务得分</option>
                <%--<option value="4T">督查组单位排名</option>--%>
            </select>
        </div>
        <div class="col-xs-1" style="right: 33px">
            <button class="btn btn-large btn-default clickMe" id="more" style="right: 65px;">更多∨</button>
        </div>
        <div class="col-xs-6" style="left: -20px;">
            <div class="pull-right">
                <button class="btn btn-large btn-danger" id="gradepoint">考核记录</button>
                <button class="btn btn-large btn-danger" id="showSummary">考核汇总</button>
            </div>
        </div>
    </div>
    <div id="more_show" class="col-xs-12 clearfix" style="margin: 5px 0px 0px 5px;" hidden>
        <button class="btn btn-large btn-success" id="exportSummary">导出报表</button>
        <button class="btn btn-large btn-default" id="downLoad">下载评分标准</button>
    </div>
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>


</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/web/js/jquery.min.js?v=2.1.4"></s:url>"></script>
<link rel="stylesheet" href="<s:url value="/assets/web/css/login/bootstrap.min.css?v=3.3.6"></s:url>">
<script src="<s:url value="/assets/web/js/jqpaginator.min.js"></s:url>"></script>
<script src="<s:url value="/assets/web/js/baseAPI.js"></s:url>"></script>

<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/scoresummary"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '序号', '考核对象', '最终得分', '排名', '所属部门', '汇总时间'];
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'sysId', index: 'sysId', width: 190, editable: true},
        {name: 'checkObject', index: 'checkObject', width: 164, editable: true},
        {name: 'score', index: 'score', width: 140, editable: true, cellattr: addCellAttr},
        {name: 'rank', index: 'rank', width: 60, editable: true, cellattr: addCellAttr},
        {name: 'checkDept', index: 'checkDept', width: 280, editable: true},
        {name: 'summaryDate', index: 'summaryDate', width: 140, editable: true}
    ];

    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: true,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        onSelectAll: function (aRowids, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });

    /**
     * 双击显示
     */
    $("#gridTable").dblclick(function (e) {
        // var id =$('#gridTable').jqGrid('getGridParam','selrow');
        showGradePointDetail();
    });

    //显示绩效详情
    function showGradePointDetail() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "任务详情",
            dialogUrl: getUrl("showGradePointDetail"),
            dialogFoot: '<button type="button" class="btn btn-default" data-dismiss="modal" onclick="myClose()">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //加载查询对话框
    // $("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    var exportData = '';
    //显示查询对话框
    var queryDialog = $("#queryDialog");

    // （新搜索）
    $("#query").click(function () {
        var url = '/scoresummary';
        var searchWord = $("#searchWord").val();
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'searchWord': searchWord}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
        query();
    });

    // 旧搜索
    // $("#query").click(function () {
    //     branchType = "";
    //     showDialog({
    //         dialogTitle: '查询对话框',
    //         dialogBody: queryDialog,
    //         dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
    //             "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
    //             "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
    //     });
    // });

    //具体查询方法
    function query() {

        exportData = $('#formDialog form').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    //更新操作
    $("#edits").click(function () {
        showEditView();
    });

    //考核汇总
    $("#showSummary").click(function () {
        window.location.href = '/scoresummary';
    });

    //考核记录
    $("#gradepoint").click(function () {
        window.location.href = '/gradepoint';
    });

    //显示创建对话框
    $("#create").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">提交审核</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //分类编辑框
    $("#createCla").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("createCla"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    /**
     * 导出表头选择
     */
    $("#exportSummary").click(function () {
        loadDialog({
            dialogTitle: '导出绩效汇总报表',
            dialogUrl: getUrl("formHead"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="exports()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    function exports() {

        var branchDeptType = $("#branchDeptType_select").val();
        var branchType;
        var departRank;
        if (branchDeptType == "0F") {
            branchType = "0";
            departRank = false;
        } else if (branchDeptType == "1F") {
            branchType = "1";
            departRank = false;
        } else if (branchDeptType == "4F") {
            branchType = "4";
            departRank = false;
        } else if (branchDeptType == "0T") {
            branchType = "0";
            departRank = true;
        } else if (branchDeptType == "1T") {
            branchType = "1";
            departRank = true;
        } else if (branchDeptType == "5") {
            branchType = "5";
            departRank = false;
        }else {
            branchType = "";
            departRank = false;
        }
        var exportData = '';//钩选表头数据
        // exportData = $('#formDialog #formHeads').serialize();
        var searchWord = $("#searchWord").val();
        var win = confirm("确认导出？");
        if (win == true) {
            exportData = $('#formDialog #formHeads').serialize();
            var url = "/export/exportSummaryPointDetail?" + exportData + "&departRank=" + departRank +
                "&branchType=" + branchType + "&searchWord=" + searchWord + "&sysIds=" + rowids;
            console.log(url);
            window.open(url);
        }
    }

    jQuery("#gridTable").jqGrid('setLabel', 0, '序号', 'labelstyle');

    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids = [];
    });
    var rowids = [];//选中行id

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };

    /**
     * 给表格字体添加样式
     * @param rowId
     * @param val
     * @param rawObject
     * @param cm
     * @param rdata
     * @returns {string}
     */
    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        return "style='color:red;font-weight:800;'";
    }

    //选择查询统计类别
    $("#branchDeptType_select").change(function () {

        var url = '/scoresummary';
        var branchDeptType = $("#branchDeptType_select").val();
        var branchType;
        var departRank;
        if (branchDeptType == "0F") {
            branchType = "0";
            departRank = false;
        } else if (branchDeptType == "1F") {
            branchType = "1";
            departRank = false;
        } else if (branchDeptType == "4F") {
            branchType = "4";
            departRank = false;
        } else if (branchDeptType == "0T") {
            branchType = "0";
            departRank = true;
        } else if (branchDeptType == "1T") {
            branchType = "1";
            departRank = true;
        } else if (branchDeptType == "5") {
            branchType = "5";
            departRank = false;
        }else {
            branchType = "";
            departRank = false;
        }
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': branchType,
                'departRank': departRank
            }, //发送数据
        }).trigger("reloadGrid"); //重新载入
    });
    //显示隐藏
    $(function () {
        //显示隐藏
        $(".clickMe").click(function () {
            if ($(this).text() === "更多∨") {
                $("#more_show").show(100);
                $(this).text("收起∧")
            } else if ($(this).text() === "收起∧") {
                $("#more_show").hide(100);
                $(this).text("更多∨");
            }
        });
    });

</script>

</body>
</html>